package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.LoginService;


@WebServlet("/login")
public class LoginServlet extends HttpServlet{
	  
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    	String username=request.getParameter("username");
	    	String password=request.getParameter("password");  
	    	
	    	//查询数据库
	    	LoginService loginService = new LoginService();
	    	boolean rs = loginService.login(username, password);
	    	
	    	if (rs) {
	    		System.out.println("登录成功");
	    		request.getRequestDispatcher("success.jsp").forward(request, response);	//重定向，可以跳到jsp
	    	}else {
	    		System.out.println("登录失败");
	    		request.getRequestDispatcher("error.jsp").forward(request, response);	//重定向，可以跳到jsp
	    	}
	    	
	    }
	}
